//
//  GXLinkCell.m
//  

#import "GXLinkCell.h"
#import "GXLinkView.h"

@interface GXLinkCell ()

@property (nonatomic, weak) GXLinkView *linkView;


@end

@implementation GXLinkCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setupUI];
    }
    return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:NO animated:animated];
}


#pragma mark - delegates






#pragma mark - setupUI
-(void) setupUI {
    //lineView
    UIView *lineView = [[UIView alloc] init];
    [self.contentView addSubview:lineView];
    
    lineView.backgroundColor = [UIColor grayColor];
    
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.leading.trailing.equalTo(self.contentView).mas_offset(0);
        make.height.mas_offset(0.5);
    }];
}







#pragma mark - setter & getter
- (void)setLinkCellList:(NSArray *)linkCellList {
    if (self.viewcontrollerEnum == ViewControllerNone) {
        return;
    }
    // 【箱,盒,瓶】
    _linkCellList = linkCellList;
    
    if (self.linkView == nil) {
        //
        GXLinkView *linkView = [GXLinkView linkViewWithControllerEnum:self.viewcontrollerEnum];
        [self.contentView addSubview:linkView];
        
        linkView.isPrefix = self.isPrefix;
        self.linkView = linkView;
    }
    
    self.linkView.titles = linkCellList;
//    [self.linkView setWidth:40 forIndex:0];
    
    if ([self.reuseIdentifier isEqualToString:@"linkPrefixCellId"] || [self.reuseIdentifier isEqualToString:@"linkPrefixAnotherCellId"]) {
        [self.linkView setWidth:40 forIndex:0];
        [self.linkView setTextAlignment:NSTextAlignmentLeft forIndex:1];
        [self.linkView setTextAlignment:NSTextAlignmentCenter forIndex:0];
    }
    
    _cellHeight = self.linkView.maxHeight;
    _cellWidth = self.linkView.maxWidth;
    
    [self.linkView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.leading.bottom.trailing.equalTo(self.contentView).mas_offset(0);
        make.height.mas_offset(_cellHeight + 5 + 1); //+margins+1
        make.width.mas_offset(_cellWidth);
    }];
    [self.contentView layoutIfNeeded];
}

//- (void)setViewcontrollerEnum:(ViewControllerEnum)viewcontrollerEnum {
//    _viewcontrollerEnum = viewcontrollerEnum;
//    
//    
//}



@end
